<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>广告位管理</title>
    <link rel="stylesheet" href="/static/assets/libs/layui/css/layui.css" />
    <link rel="stylesheet" href="/static/assets/module/admin.css?v=312" />
    <style>
        .layui-form-item {
            margin-bottom: 25px;
        }

        label .layui-icon {
            font-size: 14px;
            color: #666;
        }
    </style>
</head>

<body>
    <!-- 正文开始 -->
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-card-header">广告修改</div>
            <div class="layui-card-body">
                <form class="layui-form">
                    <input type="hidden" name="Id" value="{$info.Id}">
                    <input type="hidden" id="imgs" name="img_url" value="{$info.img_url}">
                    <input type="hidden" name="type" value="up">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">上传</label>
                            <div class="layui-input-inline">
                                <div class="layui-upload">
                                    <button type="button" class="layui-btn" id="test1">上传图片</button>
                                    <div class="layui-upload-list">
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">预览</label>
                            <div class="layui-input-block">
                                <img class="layui-upload-img" id="demo1" src="{$info.img_url}"
                                    style="width: 200px; height: 200px;">

                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">网址</label>
                            <div class="layui-input-inline">
                                <input type="text" name="url" lay-verify="required" autocomplete="off"
                                    class="layui-input" value="{$info.url}">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button class="layui-btn" lay-filter="formSubmitBas" lay-submit>&emsp;提交&emsp;</button>
                            <button type="reset" class="layui-btn layui-btn-primary">&emsp;重置&emsp;</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>

    <!-- js部分 -->
    <script type="text/javascript" src="/static/assets/libs/layui/layui.js"></script>
    <script type="text/javascript" src="/static/assets/js/common.js?v=312"></script>
    <script>
        layui.use(['layer', 'jquery', 'form', 'element', 'upload'], function () {
            var $ = layui.jquery;
            var layer = layui.layer;
            var form = layui.form;
            var element = layui.element;
            var upload = layui.upload;

            var uploadInst = upload.render({
                elem: '#test1'
                , url: "{:url('admin/system/upload')}" //改成您自己的上传接口
                , done: function (res) {
                    if (res.code == 0) {
                        $('#imgs').val(res.src);
                    }
                    if (res.code > 0) {
                        return layer.msg('上传失败');
                    }
                }, before: function (obj) {
                    //预读本地文件示例，不支持ie8
                    obj.preview(function (index, file, result) {
                        $('#demo1').attr('src', result); //图片链接（base64）
                    });
                }
                , error: function () {
                    layer.msg('上传失败');
                }
            });


            // 监听表单提交
            form.on('submit(formSubmitBas)', function (data) {
                $.ajax({
                    type: "POST",
                    url: "{:url('admin/system/ad_index')}",
                    data: data.field,
                    dataType: "json",
                    success: function (data) {
                        if (data.code == 0) {
                            layer.msg(data.msg, {
                                icon: 1,
                                time: 2000
                            }, function () {
                                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                parent.layer.close(index); //再执行关闭 
                            });


                        } else {
                            layer.alert(data.msg);
                        }
                    },
                    error: function (data) {
                        alert("请求失败");
                    }
                });

                return false;
            });

        });
    </script>
</body>

</html>